/**
 * @author monirul
 */


goog.require('goog.dom');

var PlayerDeckView =  Class.create({
	
	initialize: function(){
		this._maxNoEquipement = 5;
	},
	
	init:function(o){
		var _this = this;
		if(o['parentComponentId'] != null) this._parentComponentId = o['parentComponentId'];
		//if(o['versionNo'] != null) this._versionNo = o['versionNo'];
		this._versionNo =0;
		if(o['model'] != null) _this._model = o['model'];
		if(o['controller'] != null) _this._controller = o['controller'];
		
		
		if(o['elements'] != null){
			_this._elements = o['elements'];
		}	

		// attach model listeners
	    this._model.playerDeskInitialized.attach(function () {
	        _this.rebuild();
	    });
	    
	    this._model.playerDeskUpdated.attach(function (sender,msg) {
	    	// _this.update();
	    });
	    this._model.playerRoleInitialized.attach(function () {
	    	 _this.updateRole();
	    });
	    this._model.playerCharacterInitialized.attach(function () {
	    	 _this.updateCharacter();
	    });
	   
	    this._model.playerLifeCountUpdated.attach(function () {
	    	// _this.updateLifeCount();
	    });
	    this._model.gameReadyToStart.attach(function () {
	    	 _this.readyToStart();
	    });
	   
	},
	
	
	
	updateCharacter:function(){
		this._characterElement = $(this.playerId +"_character");
		this._characterElement.innerHTML = this._model.getCharacter();
		$("btnStart").disabled = "";
		$("btnGetCharacter").disabled = "disabled";
	},
	
	
	
	_initDom: function(){
		this.playerId = this._model.getPlayerId();
		var player = this._model.getPlayer();
		this.equipementCards = [];
		var armStyle = "height: 80%;width:15%;background-color: #003300;border: 2px;float:left;margin: 2px;";
		this.equipementDeck  = goog.dom.createDom('div', {'style': 'width:100%;height:40%','id':this.playerId +"_equipement"},'');
		for(var i=0;i<this._maxNoEquipement;i++){
			//var element = goog.dom.createDom('div', {'style': armStyle,'id':this.playerId+'_arm_'+i},'')
			//this.equipementCards.push(goog.dom.createDom('div', {'style': armStyle,'id':this.playerId+'_arm_'+i},''));//);
			goog.dom.appendChild(this.equipementDeck,goog.dom.createDom('div', {'style': armStyle,'id':this.playerId+'_arm_'+i},''));
		}
//		
		this.lifeCountBar = [];
		this.lifeCountPanel  = goog.dom.createDom('div', {'style': '','id':this.playerId +"_lifeCountPanel"},'');
		var hpStyle = "height: 10px;width:10px;border: 2px;float:left;margin: 2px;background-color:#FF0000";
		for(var i=0;i<this._model.getLifeCount();i++){
			//this.lifeCountBar.push(goog.dom.createDom('div', {'style': hpStyle,'id':this.playerId+'_hp_'+i},''));
			goog.dom.appendChild(this.lifeCountPanel, goog.dom.createDom('div', {'style': hpStyle,'id':this.playerId+'_hp_'+i},''));
		}
//		
		this.gameCardsOppositeSide = [];
		this.gameCardDeck  = goog.dom.createDom('div', {'style': 'width:100%;height:40%','id':this.playerId +"_gameCradDeck"},'');
		var gameCardStyle = "height:80%;width:15%;background-color: green;border: 2px;float:left;margin: 2px;";
		for(var i=0;i<this._model.getCardCount();i++){
//			this.gameCardsOppositeSide.push(goog.dom.createDom('div', {'style': gameCardStyle,'id':this.playerId+'_gamecard_'+i},''));
			goog.dom.appendChild(this.gameCardDeck,goog.dom.createDom('div', {'style': gameCardStyle,'id':this.playerId+'_gamecard_'+i},''));
		}
//		
		this.name  = goog.dom.createDom('span', {'id':this.playerId +"_name",'style':'padding:0px;float:right;'},this._model.getPlayer().name);
		this.role  = goog.dom.createDom('span', {'id':this.playerId +"_role",'style':'padding:0px;float:right;'},this._model.getRole());
		this.character  = goog.dom.createDom('span', {'id':this.playerId +"_character",'style':'padding:0px;float:right;'},this._model.getCharacter());
		
		this.userRoleCharacterPanel  = goog.dom.createDom('div', {'style':this.playerId +"_",'id':''},this.name,this.role,this.character);
		
		
		this.userDetail  = goog.dom.createDom('div', {'style': 'width:100%;;height:20%','id':this.playerId +"_userDetailDeck"},this.lifeCountPanel,this.userRoleCharacterPanel);
		
		this.playerDeck  = goog.dom.createDom('div', {'style': 'border:1px sloid red;width:100%;;height:100%','id':this.playerId +"_playerDeck"},this.equipementDeck,this.userDetail,this.gameCardDeck);
		this._targetLocation = $(this._elements.targetLocation);
		goog.dom.appendChild(this._targetLocation, this.playerDeck);
//		this._targetLocation.appendChild(this.playerDeck);
	},
	
	show : function () {
        this.rebuild();
	},
	
	
	
	rebuild: function() {
		this._initDom();
	}
	
});
